package sismatriculas;

import BE.MenuBE;
import BR.MenuBR;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

public class frmPrincipal extends javax.swing.JFrame {
private List<MenuBE> listamenu = new ArrayList(); //para leer los menus principales
 private JMenu Menuprincipal;

private List<MenuBE> listaSubMenu = new ArrayList();
private JMenuItem SubMenu;

    frmUsuariosSistema UsuarioSistema; //declarando los SubFormularios
    frmInternal2 internal2;
    frmAlumno internal3;
    frmUbigeo ubigeo;
    public frmPrincipal() {
        //this.setResizable(false);
        initComponents();
        
        this.setExtendedState(MAXIMIZED_BOTH);
        UsuarioSistema = new frmUsuariosSistema();
        internal2 = new frmInternal2();
        internal3 = new frmAlumno();
        ubigeo = new frmUbigeo();

        MenuBR menus = new MenuBR();
        listamenu = menus.lista_MenuPrinciapal();
        //listaSubMenu=menus.lista_SubMenu();

        for(MenuBE x : listamenu){
         String nombre = x.getNombre_menu();
         int cod = x.getId_menu();
        Menuprincipal = new JMenu(); //crear objeto
        Menuprincipal.setName(nombre);
        Menuprincipal.setText(nombre);
        menuBar.add(Menuprincipal);
        listaSubMenu = menus.lista_SubMenu(cod);
            //---------------- SUB MENU -------------------------
            for(MenuBE y : listaSubMenu){
             String nombresub = y.getNombre_menu();
             int n1 = y.getId_menu();
             int n2=y.getId_menusup();
             String orden = y.getOrden();
             String ubicacion;

             //while(n2!=n1){
             SubMenu = new JMenuItem(); //crear objeto
             SubMenu.setName(nombresub);
             SubMenu.setText(nombresub);
             Menuprincipal.add(SubMenu);
             //}
            }

        }
        
    } 
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        desktopPane = new javax.swing.JDesktopPane();
        menuherramientas = new javax.swing.JToolBar();
        btnInternal1 = new javax.swing.JButton();
        btnInternal2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        btnubigeo = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        menuArchivo = new javax.swing.JMenu();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle(".:: Sistema de Matriculas y Notas ::.");

        desktopPane.setBackground(new java.awt.Color(240, 240, 240));
        desktopPane.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        desktopPane.setForeground(new java.awt.Color(240, 240, 240));

        menuherramientas.setRollover(true);

        btnInternal1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recursos/user-32.png"))); // NOI18N
        btnInternal1.setFocusable(false);
        btnInternal1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnInternal1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnInternal1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInternal1ActionPerformed(evt);
            }
        });
        menuherramientas.add(btnInternal1);

        btnInternal2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recursos/chair-32.png"))); // NOI18N
        btnInternal2.setFocusable(false);
        btnInternal2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnInternal2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnInternal2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInternal2ActionPerformed(evt);
            }
        });
        menuherramientas.add(btnInternal2);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recursos/Profile.png"))); // NOI18N
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        menuherramientas.add(jButton1);

        btnubigeo.setText("Ubigeo");
        btnubigeo.setFocusable(false);
        btnubigeo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnubigeo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnubigeo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnubigeoActionPerformed(evt);
            }
        });
        menuherramientas.add(btnubigeo);

        menuArchivo.add(jSeparator1);

        menuBar.add(menuArchivo);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(menuherramientas, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 790, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 780, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(menuherramientas, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)
                .addGap(20, 20, 20))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnInternal1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInternal1ActionPerformed
        desktopPane.add(UsuarioSistema);
        if (UsuarioSistema.isVisible() == false) {
            UsuarioSistema.setVisible(true);
        }
        //internal1.GenerarCod();
    }//GEN-LAST:event_btnInternal1ActionPerformed

    private void btnInternal2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInternal2ActionPerformed
        desktopPane.add(internal2);
        if (internal2.isVisible() == false) {
            internal2.setVisible(true);
        }
    }//GEN-LAST:event_btnInternal2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        internal3.principal = this;
        desktopPane.add(internal3);
        if (internal3.isVisible()==false) {
            internal3.setVisible(true);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void btnubigeoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnubigeoActionPerformed
   desktopPane.add(ubigeo);
        if (ubigeo.isVisible() == false) {
            ubigeo.setVisible(true);
        }
    }//GEN-LAST:event_btnubigeoActionPerformed

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new frmPrincipal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnInternal1;
    private javax.swing.JButton btnInternal2;
    private javax.swing.JButton btnubigeo;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JDesktopPane desktopPane;
    private javax.swing.JButton jButton1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JMenu menuArchivo;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JToolBar menuherramientas;
    // End of variables declaration//GEN-END:variables
}
